package com.teach.controller.shop;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.teach.dto.CommentsSearch;
import com.teach.dto.LoginUser;
import com.teach.dto.ProductAndShopSlide;
import com.teach.entity.ProductClass;
import com.teach.entity.ShopAddress;
import com.teach.entity.ShopSlide;
import com.teach.mapper.ShopAddressMapper;
import com.teach.service.CommentsService;
import com.teach.service.shop.ShopAddressService;
import com.teach.service.shop.ShopGoodsService;
import com.teach.service.shop.ShopIndexService;
@Controller
public class ShopIndexController {
	
	List<ProductClass> productclass; 
	List<ShopSlide> shopSlide;
	List<ProductAndShopSlide> pands;
	
	@Autowired
	ShopIndexService sis;
	
	@Autowired
	private ShopGoodsService service;
	@Autowired
	private CommentsService service1;
	
	@GetMapping("/shop.html")
	public String doShop(Model model) {
		productclass = sis.findAll();
		shopSlide = sis.slideFindAll();
		pands = sis.pandsFindAll();
		model.addAttribute("productclass", productclass);
		model.addAttribute("shopSlide", shopSlide);
		model.addAttribute("pands", pands);
		return "shop/index";
	}
	
	@GetMapping("/userMain.page")
	public String doUserMain() {
		return "shop/userMain";
	}
	
	//退出登录
	@RequestMapping("/shop-logout.do")
	public String doLogout(HttpSession session){
		session.invalidate();
		return "shop/index";
	}
		
	//商品详情
	@GetMapping("/shopgoods-{current}.do")
	public String doShopGoods(Model model,Long productId,@PathVariable Integer current) {
		model.addAttribute("product", service.get(productId));
		CommentsSearch search=new CommentsSearch();
		search.setCommentCommentator(productId);
		search.setCurrent(current);
		model.addAttribute("xihuan", service.selectByProductID(productId));
		model.addAttribute("pinlun",service1.commentsPage(search));
		return "shop/goods";
	}
}
